import Cookies from 'js-cookie';
export default ({
    namespaced: true,
    state: {
        ChoiceNum: 1,//1 选择界面   2 邮箱登录    3.手机登录    4 注册
        isShowLoginBox: true,
        userInfo: null,//用户信息
    },
    mutations: {
        change_ChoiceNum(start, data) {
            start.ChoiceNum = data;
        },
        change_isShowLoginBox(start, data) {
            start.isShowLoginBox = data;
        },
        change_userInfo(start, data) {
            start.userInfo = data;
        },
    },
    actions: {
        setChange_ChoiceNum({ dispatch, commit }, data) {
            commit('change_ChoiceNum', data)
        },
        setChange_isShowLoginBox({ dispatch, commit }, data) {
            commit('change_isShowLoginBox', data)
        },
        //登录使用
        setChange_userInfo({ dispatch, commit }, data) {
            Cookies.set('token', data.token)
            commit('change_userInfo', data)
        },
        //退出登录
        loginOut({ dispatch, commit }) {
            Cookies.remove('token')
            commit('change_userInfo', null)
        },
    },
    getters: {
        isLogin: state => {//登录状态
            return !!state.userInfo?.token;
        }
    }
})
